<template>
	<view v-show="!isSortType" :style="{padding:'0 '+prConfig+'px'}">
		<!-- <view class="seckillList acea-row row-between-wrapper">
			<view class="priceTag">
				<image src="../../activity/static/priceTag.png"></image>
			</view>
			<view class='timeLsit'>
				<scroll-view class="scroll-view_x" scroll-x scroll-with-animation :scroll-left="scrollLeft" style="width:auto;overflow:hidden;height:106rpx;" :scroll-into-view="intoindex"  v-if="seckillList.length">
					<block v-for="(item,index) in timeList" :key='index'>
						<view @tap='settimeList(item,index)' class='item' :class="active == index?'on':''" :id='"sort"+index'>
							<view class='time'>{{item.time}}</view>
							<view class="state">{{item.state}}</view>
						</view>
					</block>
				</scroll-view>
			</view>
		</view> -->
		<view class="index-product-wrapper" :class="bgStyle===0?'':'borderRadius15'"
			:style="{ marginTop: mbConfig*2 + 'rpx'}" v-if="seckillList.length">
			<!-- 单列 -->
			<block v-if="itemStyle == 0">
				<view class="list-box listA list" :class="seckillList.length > 0 ? 'fadeIn on' : ''">
					<view class="item" :class="conStyle?'borderRadius15':''" v-for="(item, index) in seckillList" :key="index"
						@click="goDetail(item)">
						<view class="pictrue">
							<span class="pictrue_log pictrue_log_class" :style="'background-color:'+labelColor"
								v-if="item.activity && item.activity.type === '1'">抢单</span>
							<span class="pictrue_log pictrue_log_class" :style="'background-color:'+labelColor"
								v-if="item.activity && item.activity.type === '2'">砍价</span>
							<span class="pictrue_log pictrue_log_class" :style="'background-color:'+labelColor"
								v-if="item.activity && item.activity.type === '3'">拼团</span>
							<image :src="item.image" mode="aspectFill"></image>
						</view>
						<view class="text-info"
							style="display: flex; flex-direction: column; justify-content: space-between;">
							<!-- <view>
								<view class="title line2" v-if="titleShow">{{ item.store_name }}</view>
								<view class="old-price" v-if="opriceShow">
									<text>¥</text>
									{{ item.ot_price }}
								</view>
							</view> -->
							<view class='text acea-row row-column-around'>
								<view class='name line1'>{{item.title}}</view>
								<view class="limit">限量 <text
										class="limitPrice">{{item.quota_show}}{{item.unit_name || ''}}</text></view>
								<view class="progress">
									<view class='bg-reds' :style="'width:'+item.percent+'%;'"></view>
									<view class='piece'>已抢{{item.percent}}%</view>
								</view>
								<view class='money'>
									<text class="y_money">市场价：{{item.ot_price}}</text>
									<text class='num font-color'>￥<text>{{item.price}}</text></text>
								</view>

							</view>
							<view class='grab bg-color' v-if="seckillStatus == item.time_id">马上抢</view>
							<view class='grab bg-color-hui' v-else-if="seckillStatus != item.time_id && index>active">即将开始</view>
							<view class='grab bg-color-hui' v-else>已结束</view>
							<!-- <view class='grab bg-color'v-if="seckillStatus==1">马上抢</view> -->


							<!-- <view class="price" :style="'color:'+fontColor">
								<view v-if="priceShow">
									<text>￥</text>
									{{ item.price }}
								</view>
								<view class="txt" :style="'border:1px solid '+labelColor+';color:'+labelColor" :class="priceShow?'':'on'" v-if="item.checkCoupon && couponShow">券</view>
							</view> -->
						</view>
					</view>
				</view>
			</block>
			<!-- 两列 -->
			<block v-if="itemStyle == 1">
				<view class="list-box listC" :class="tempArr.length > 0 ? 'fadeIn on' : ''">
					<view class="item" :class="conStyle?'borderRadius15':''" v-for="(item, index) in tempArr"
						:key="index" @click="goDetail(item)">
						<view class="pictrue">
							<span class="pictrue_log pictrue_log_class" :style="'background-color:'+labelColor"
								v-if="item.activity && item.activity.type === '1'">抢单</span>
							<span class="pictrue_log pictrue_log_class" :style="'background-color:'+labelColor"
								v-if="item.activity && item.activity.type === '2'">砍价</span>
							<span class="pictrue_log pictrue_log_class" :style="'background-color:'+labelColor"
								v-if="item.activity && item.activity.type === '3'">拼团</span>
							<image :src="item.image" mode="aspectFill"></image>
						</view>
						<view class="text-info">
							<view class="title line1" v-if="titleShow">{{ item.store_name }}</view>
							<view class="old-price" v-if="opriceShow">
								<text>¥</text>
								{{ item.ot_price }}
							</view>
							<view class="price" :style="'color:'+fontColor">
								<view v-if="priceShow">
									<text>￥</text>
									{{ item.price }}
								</view>
								<view class="txt" :style="'border:1px solid '+labelColor+';color:'+labelColor"
									:class="priceShow?'':'on'" v-if="item.checkCoupon && couponShow">券</view>
							</view>
						</view>
					</view>
				</view>
			</block>
			<!-- 三列 -->
			<block v-if="itemStyle == 2">
				<view class="list-box listB" :class="tempArr.length > 0 ? 'fadeIn on' : ''">
					<view class="item" :class="conStyle?'borderRadius15':''" v-for="(item, index) in tempArr"
						:key="index" @click="goDetail(item)">
						<view class="pictrue">
							<span class="pictrue_log pictrue_log_class" :style="'background-color:'+labelColor"
								v-if="item.activity && item.activity.type === '1'">抢单</span>
							<span class="pictrue_log pictrue_log_class" :style="'background-color:'+labelColor"
								v-if="item.activity && item.activity.type === '2'">砍价</span>
							<span class="pictrue_log pictrue_log_class" :style="'background-color:'+labelColor"
								v-if="item.activity && item.activity.type === '3'">拼团</span>
							<image :src="item.image" mode="aspectFill"></image>
						</view>
						<view class="text-info"
							style="display: flex; flex-direction: column; justify-content: space-between;">
							<view>
								<view class="title line1" v-if="titleShow">{{ item.store_name }}</view>
								<view class="old-price" v-if="opriceShow">
									<text>¥</text>
									{{ item.ot_price }}
								</view>
							</view>
							<view class="price" :style="'color:'+fontColor">
								<view v-if="priceShow">
									<text>￥</text>
									{{ item.price }}
								</view>
								<view class="txt" :style="'border:1px solid '+labelColor+';color:'+labelColor"
									:class="priceShow?'':'on'" v-if="item.checkCoupon && couponShow">券</view>
							</view>
						</view>
					</view>
				</view>
			</block>
		</view>
		<!-- 大图 -->
		<block v-if="itemStyle == 3 && tempArr.length" :style="{ marginTop: mbConfig + 'rpx' }">
			<view class="listBig" :class="bgStyle===0?'':'borderRadius15'" :style="{ background: themeColor }">
				<view class="itemBig" :class="conStyle?'borderRadius15':''" v-for="(item,index) in tempArr" :key="index"
					@click="goDetail(item)">
					<view class="img-box">
						<span class="pictrue_log_big pictrue_log_class" :style="'background-color:'+labelColor"
							v-if="item.activity && item.activity.type === '1'">抢单</span>
						<span class="pictrue_log_big pictrue_log_class" :style="'background-color:'+labelColor"
							v-if="item.activity && item.activity.type === '2'">砍价</span>
						<span class="pictrue_log_big pictrue_log_class" :style="'background-color:'+labelColor"
							v-if="item.activity && item.activity.type === '3'">拼团</span>
						<image :src="item.recommend_image" mode="aspectFill" v-if="item.recommend_image"></image>
						<image :src="item.image" mode="aspectFill" v-else></image>
					</view>
					<view class="name line2"><span class="coupon"
							:style="'border:1px solid '+labelColor+';color:'+labelColor"
							v-if="item.checkCoupon && couponShow">券</span><span
							v-if="titleShow">{{item.store_name}}</span></view>
					<view class="price" :style="'color:'+fontColor"><span v-if="priceShow">￥<span
								class="num">{{item.price}}</span></span><span class="old-price"
							v-if="opriceShow">¥{{item.ot_price}}</span></view>
				</view>
			</view>
		</block>
		<view class='noCommodity' v-if="seckillList.length == 0 && (page != 1 || active== 0)">
			<view class='pictrue'>
				<image src='/static/images/noShopper.png'></image>
			</view>
		</view>
	</view>
</template>

<script>
	import {
		getProductslist
	} from '@/api/store.js';
	import {
		getSeckillIndexTime,
		getSeckillList
	} from '@/api/activity.js';
	export default {
		name: 'goodList',
		props: {
			dataConfig: {
				type: Object,
				default: () => {}
			},
			isSortType: {
				type: String | Number,
				default: 0
			}
		},
		data() {
			return {
				datatime: '',
				status: '',
				active: 5,
				tempArr: [],
				spikeList: [],
				seckillList: [],
				countDownHour: "00",
				countDownMinute: "00",
				countDownSecond: "00",
				page: 1,
				limit: 8,
				loading: false,
				loadend: false,
				pageloading: false,
				scrollLeft: 0,
				intoindex: '',
				timeList: [],
				mbConfig: this.dataConfig.mbConfig.val,
				numConfig: this.dataConfig.numConfig.val,
				themeColor: this.dataConfig.themeColor.color[0].item,
				itemStyle: this.dataConfig.itemStyle.type,
				sortType: this.dataConfig.goodsSort.type,
				type: this.dataConfig.tabConfig.tabVal || 0,
				selectId: this.dataConfig.selectConfig.activeValue,
				productIds: this.dataConfig.goodsList.ids || [],
				opriceShow: this.dataConfig.opriceShow.val, //商品原价
				priceShow: this.dataConfig.priceShow.val, //商品价格
				titleShow: this.dataConfig.titleShow.val, //商品名称
				couponShow: this.dataConfig.couponShow.val, //商品提货卡
				prConfig: this.dataConfig.prConfig.val, //左右边距
				bgStyle: this.dataConfig.bgStyle.type, //背景样式
				conStyle: this.dataConfig.conStyle.type, //内容样式
				fontColor: this.dataConfig.fontColor.color[0].item,
				labelColor: this.dataConfig.labelColor.color[0].item,
				baURL: '../../../static/images/Index_banner5.png',
				seckillStatus:1,
			};
		},
		created() {},
		mounted() {
			this.productslist();
			this.getSeckillConfig();
			// this.getSeckillIndexTime();
		},
		onLoad() {
			this.getSeckillConfig();
		},
		methods: {
			getSeckillConfig: function() {
				let that = this;
				getSeckillIndexTime().then(res => {
					that.topImage = res.data.lovely;
					that.timeList = res.data.seckillTime;
					console.log(that.timeList.length);
					that.active = res.data.seckillTimeIndex;
					that.$nextTick(() => {
						that.intoindex = 'sort' + res.data.seckillTimeIndex
					})
					if (that.timeList.length) {
						// wxh.time(that.data.timeList[that.data.active].stop, that);
						that.scrollLeft = (that.active - 1.37) * 100
						setTimeout(function() {
							that.loading = true
						}, 2000);
						that.seckillList = [],
							that.page = 1
						that.seckillStatus = that.timeList[that.active].id
						console.log(that.timeList[that.active].id)
						that.getSeckillList();
					}
				});
			},
			settimeList: function(item, index) {
				var that = this;
				this.active = index
				if (that.interval) {
					clearInterval(that.interval);
					that.interval = null
				}
				that.interval = 0,
					that.countDownHour = "00";
				that.countDownMinute = "00";
				that.countDownSecond = "00";
				// that.seckillStatus = that.timeList[that.active].status;
				that.loadend = false;
				that.page = 1;
				that.seckillList = [];
				// wxh.time(e.currentTarget.dataset.stop, that);
				that.getSeckillList();
			},
			getSeckillList: function() {
				var that = this;
				var data = {
					page: that.page,
					limit: that.limit,
					type: that.seckillStatus
				};
				if (that.loadend) return;
				if (that.pageloading) return;
				this.pageloading = true
				getSeckillList(that.timeList[that.active].id, data).then(res => {
					var seckillList = res.data
					var loadend = seckillList.length < that.limit;
					that.page++;
					that.seckillList = that.seckillList.concat(seckillList),
						that.page = that.page;
					that.pageloading = false;
					that.loadend = loadend;
				}).catch(err => {
					that.pageloading = false
				});
			},
			getSeckillIndexTime() {
				let limit = this.$config.LIMIT;
				let params = {
					page: 1,
					limit: this.numberConfig >= limit ? limit : this.numberConfig,
					type: 'index'
				}
				getSeckillIndexTime().then(res => {
					if (res.data.seckillTimeIndex === -1) {
						return;
					}

					this.datatime = res.data.seckillTime[res.data.seckillTimeIndex].stop;
					this.status = res.data.seckillTime[res.data.seckillTimeIndex].status;
					let id = res.data.seckillTime[res.data.seckillTimeIndex].id
					getSeckillList(id, params).then(({
						data
					}) => {
						data.forEach((item) => {
							let num = 0
							if (item.price > 0 && item.ot_price > 0) num = ((parseFloat(item
								.price) / parseFloat(item.ot_price)).toFixed(
								2))
							item.discountNum = this.$util.$h.Mul(num, 10)
						})
						this.spikeList = data
					})
				})
			},
			productslist() {
				let limit = this.$config.LIMIT;
				let data = {};
				if (this.type == 1) {
					data = {
						ids: this.productIds.join(','),
					};
				} else {
					data = {
						priceOrder: this.sortType == 2 ? 'desc' : '',
						salesOrder: this.sortType == 1 ? 'desc' : '',
						selectId: this.selectId[this.selectId.length - 1] || 0,
						limit: this.numConfig
					};
				}
				// getProductslist(data).then(res => {
				// 	this.tempArr = res.data;
				// });
			},
			goDetail(item) {
				uni.navigateTo({
					url: '/pages/activity/goods_seckill_details/index?id=' + item.id + '&time=' + this.datatime +
						'&status=' + this.status
				})
				// this.$emit('detail', item);
			}
		}
	};
</script>

<style lang="scss">
	.seckillList {
		padding: 0 20rpx;
	}

	.seckillList .priceTag {
		width: 75rpx;
		height: 70rpx;
	}

	.seckillList .priceTag image {
		width: 100%;
		height: 100%;
	}

	.timeLsit {
		// width: 610rpx;
		width: 100%;
		white-space: nowrap;
		margin: 30rpx 0;
	}

	.timeLsit .item {
		display: inline-block;
		font-size: 20rpx;
		color: #666;
		text-align: center;
		padding: 11rpx 0;
		box-sizing: border-box;
		height: 96rpx;
		margin-right: 35rpx;
	}

	.timeLsit .item .time {
		font-size: 36rpx;
		font-weight: 600;
		color: #333;
	}

	.timeLsit .item.on .time {
		color: var(--view-theme);
	}

	.timeLsit .item.on .state {
		width: 90rpx;
		height: 30rpx;
		border-radius: 15rpx;
		background: var(--view-theme);
		color: #fff;
	}

	.list .item {
		height: 230rpx;
		position: relative;
		width: 710rpx;
		margin: 0 auto 20rpx auto;
		background-color: #fff;
		border-radius: 20rpx;
		padding: 0 5rpx;
	}

	.list .item .pictrue {
		width: 180rpx;
		height: 180rpx;
		border-radius: 10rpx;
	}

	.list .item .pictrue image {
		width: 100%;
		height: 100%;
		border-radius: 10rpx;
	}

	.list .item .text {
		width: 400rpx;
		font-size: 30rpx;
		color: #333;
		height: 186rpx;
	}

	.list .item .text .name {
		width: 100%;
	}

	.list .item .text .money {
		font-size: 30rpx;
		color: #E93323;
	}

	.list .item .text .money .num {
		font-size: 40rpx;
		font-weight: 500;
		font-family: 'Guildford Pro';
	}

	.list .item .text .money .y_money {
		font-size: 24rpx;
		color: #999;
		text-decoration-line: line-through;
		margin-left: 60rpx;
	}

	.list .item .text .limit {
		font-size: 22rpx;
		color: #999;
		margin-bottom: 5rpx;
	}

	.list .item .text .limit .limitPrice {
		margin-left: 10rpx;
	}

	.progress {
		overflow: hidden;
		background-color: #FFEFEF;
		width: 240rpx;
		border-radius: 18rpx;
		height: 30rpx;
		position: relative;
	}

	.progress .bg-reds {
		width: 0;
		height: 100%;
		transition: width 0.6s ease;
		background: linear-gradient(90deg, rgba(233, 51, 35, 1) 0%, rgba(255, 137, 51, 1) 100%);
	}

	.progress .piece {
		position: absolute;
		left: 8%;
		transform: translate(0%, -50%);
		top: 49%;
		font-size: 16rpx;
		color: #FFB9B9;
	}

	.grab {
		font-size: 28rpx;
		color: #fff;
		width: 150rpx;
		height: 54rpx;
		border-radius: 27rpx;
		text-align: center;
		line-height: 54rpx;
		position: absolute;
		right: 20rpx;
		bottom: 30rpx;
		background: #bbbbbb;
	}

	.listBig {
		padding: 1px 20rpx 20rpx 20rpx;

		.borderRadius15 {
			image {
				border-radius: 20rpx 20rpx 0 0;
			}
		}

		.itemBig {
			width: 100%;
			margin-top: 20rpx;
			background-color: #fff;
			padding-bottom: 15rpx;

			.img-box {
				width: 100%;
				height: 284rpx;
				position: relative;

				.pictrue_log_big {
					border-radius: 20rpx 0 20rpx 0;
				}

				image {
					width: 100%;
					height: 100%;
				}
			}

			.name {
				font-size: 28rpx;
				font-weight: bold;
				margin-top: 16rpx;
				padding: 0 8px;

				.coupon {
					display: inline-block;
					text-align: center;
					width: 32rpx;
					border-radius: 4rpx;
					font-size: 20rpx;
					font-weight: normal;
					margin-right: 10rpx;
				}
			}

			.price {
				font-weight: bold;
				font-size: 12px;
				margin-top: 10rpx;
				padding: 0 8px;

				.num {
					font-size: 32rpx;
					margin-right: 10rpx;
				}

				.old-price {
					color: #aaa;
					font-weight: normal;
					text-decoration: line-through;
				}
			}
		}
	}

	.index-product-wrapper {

		.list-box {
			display: flex;
			flex-wrap: wrap;
			justify-content: space-between;
			padding: 20rpx 20rpx 500rpx 20rpx;

			.item {
				width: 345rpx;
				margin-bottom: 20rpx;
				background-color: #fff;
				position: relative;

				&.on {
					border-radius: 0;
				}

				.pictrue {
					width: 347rpx;
					height: 347rpx;
				}

				.pictrue_log {
					width: 92rpx;
					height: 44rpx;
					font-size: 26rpx;
					line-height: 44rpx;
					border-radius: 0 0 20rpx 0 !important;
				}

				image {
					width: 100%;
					// height: 346rpx;
					height: 100%;
					display: block;
				}

				.text-info {
					padding: 10rpx 20rpx 15rpx;

					.title {
						color: #222222;
					}

					.old-price {
						margin-top: 4rpx;
						font-size: 26rpx;
						color: #aaaaaa;
						text-decoration: line-through;

						text {
							margin-right: 2px;
							font-size: 20rpx;
						}
					}

					.price {
						display: flex;
						align-items: flex-end;
						font-size: 36rpx;
						font-weight: 550;

						text {
							padding-bottom: 4rpx;
							font-size: 26rpx;
							font-weight: normal;
						}

						.txt {
							display: flex;
							align-items: center;
							justify-content: center;
							width: 28rpx;
							height: 28rpx;
							margin-left: 15rpx;
							margin-bottom: 10rpx;
							border-radius: 4rpx;
							font-size: 20rpx;
							font-weight: normal;

							&.on {
								margin-left: 0;
							}
						}
					}
				}
			}

			&.on {
				display: flex;
			}

			&.listA {
				display: flex;
				justify-content: space-between;
				background: none;
				padding: 0;

				.item {
					width: 48%;
					height: 436rpx;
					background-image: url('~@/static/images/Index_banner5.png');
					background-color: initial;
					background-repeat: no-repeat;
					background-size: cover;
					background-position: center;
					padding: 45rpx 30rpx;
					margin: 0;
					margin-top: 35rpx;
					.text-info {
						padding: 10rpx 0 0 0;
						
						.grab {
							width: 117rpx;
							height: 40rpx;
							line-height: 40rpx;
							background-color: #f97205 !important;
							border-radius: 10rpx;
							right: 25rpx;
							bottom: 58rpx;
						}
						.bg-color-hui{
							background: #bbb!important;
						}
					}



					.text {
						width: 100%;
						font-size: 24rpx;
						display: block;

						.limit {
							font-size: 22rpx;
							color: #df2e26;
						}

						.progress {
							width: 100%;
						}

						.money {
							margin-top: 20rpx;

							.y_money {
								width: 100%;
								display: block;
								margin-left: 0;
								font-size: 22rpx;
								color: #999999;
							}

							.num {
								font-size: 28rpx;

								text {
									font-size: 33rpx;
								}
							}
						}
					}

					.pictrue {
						width: 275rpx;
						height: 145rpx;
					}

					.text-info {
						// width: 490rpx;
						flex: 1
					}
				}
			}

			&.listC {
				.item {
					width: 48.5%;
				}

				.pictrue {
					width: 100%;
					height: 345rpx;
				}
			}

			&.listB {
				justify-content: inherit;

				.item {
					width: 31.6%;
					margin-right: 16rpx;

					.pictrue {
						width: 100%;
						height: 220rpx;
					}

					&:nth-child(3n) {
						margin-right: 0;
					}
				}
			}
		}
	}
</style>
